/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JPnlSignals.java
 *
 * Created on 06/03/2010, 14:09:55
 */
package systole.view.tabs.patientsignals;

import java.text.DecimalFormat;
import javax.swing.JPanel;
import org.jdesktop.application.Action;
import systole.domain.signals.Segment;
import systole.processor.filters.FilterProcessor;
import systole.processor.filters.FilterSettings;
import systole.processor.filters.LowPass;
import systole.processor.filters.RemezEquiripple;
import systole.view.charts.XYChart;
import systole.view.tabs.controllers.AnalysisController;


/**
 *
 * @author jmj
 */
public class JPnlFilteringDetails extends javax.swing.JPanel {



    /**
	 * 
	 */
	private static final long serialVersionUID = 562847837904879885L;

    private AnalysisController logic;

    private XYChart filteredSignal;
    private XYChart filterChart;

    private final DecimalFormat formatter = new DecimalFormat("#0.00##");


	/** Creates new form JPnlSignalshee
	 * @param parent 
     * 
     */
    public JPnlFilteringDetails(AnalysisController parent) {
        this.logic = parent;
        initComponents();
        this.btnApplyFilter.setEnabled(false);
    }

    /**
     * @return PnlProccesedSignal
     */
    public JPanel getjPnlFilterConfiguration() {
        return jPnlFilterConfig;
    }

    /**
     * @return PnlRawSignal
     */
    public JPanel getjPnlFilteredSignal() {
        return jPnlFilteredSignal;
    }


    private XYChart buildFilterScheme(int maxFrequency){

        //Construccion del grafico representativo de un filtro pasabajos
        XYChart filter = new XYChart("Filtro PasaBajos","Frecuencias (Hz)","Amplitud (dB)");
        double[] dataset = new double[maxFrequency];

        int i,db;
        for (i = 0, db = 0; i < 17; i++){ dataset[i] = 0;}                  //Los primeros 17 valores son 0db
        for (i = 17; i < 20; i++, db--){ dataset[i] = db - 1;}              //Del 17 al 20 caen a -3db
        for (i = 20, db = -20; i < dataset.length; i++){ dataset[i] = db;}  //Del 20 en adelante valen -20db
        filter.addSeries("", dataset, 1);
        filter.setShowLegend(false);
        
        return filter;

    }

    /**
     * @param filteredSignal
     */
    public void createFilterDetails(XYChart filteredSignal){

       /* FilterSettings settings = this.logic.getDefaultIndicators();//this.logic.getFilterIndicators();

        this.filteredSignal = filteredSignal;
        ChartPanel cp = this.filteredSignal.plot();
        cp.getChart().setTitle("Señal Filtrada - Vista Previa");
        
        this.getjPnlFilteredSignal().removeAll();
        this.getjPnlFilteredSignal().add(cp);

        int fs2 = (new Double(settings.getFilt().getSamplingFrequency()*1000 / 2)).intValue();
        
        this.filterChart = this.buildFilterScheme(fs2);
        this.getJPnlFreqChart().removeAll();
        this.getJPnlFreqChart().add(this.filterChart.plot());

        this.loadSettingsInForm(settings);*/

    }

    

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jSplitPnl = new javax.swing.JSplitPane();
        jPnlFilteredSignal = new javax.swing.JPanel();
        jPnlFilterConfig = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        jPnlFreqChart = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        btnPreviewFilter = new javax.swing.JButton();
        btnRestoreDefaults = new javax.swing.JButton();
        btnApplyFilter = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        jLabel9 = new javax.swing.JLabel();
        lblSamplingFrequency = new javax.swing.JLabel();
        lblFilterType = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        lblSamplingPeriod = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        lblAlgorithm = new javax.swing.JLabel();
        jPanel6 = new javax.swing.JPanel();
        txtTransitionBandwidth = new javax.swing.JFormattedTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        spinFilterOrder = new javax.swing.JSpinner();
        jLabel5 = new javax.swing.JLabel();
        spinFilterIterations = new javax.swing.JSpinner();
        jLabel2 = new javax.swing.JLabel();
        spinCutoff = new javax.swing.JSpinner();
        txtAttenuation = new javax.swing.JFormattedTextField();
        txtRipple = new javax.swing.JFormattedTextField();
        jLabel4 = new javax.swing.JLabel();
        jXHeader1 = new org.jdesktop.swingx.JXHeader();

        setName("Form"); // NOI18N
        setPreferredSize(new java.awt.Dimension(500, 532));

        jSplitPnl.setDividerLocation(275);
        jSplitPnl.setDividerSize(1);
        jSplitPnl.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
        jSplitPnl.setLastDividerLocation(275);
        jSplitPnl.setName("jSplitPnl"); // NOI18N

        jPnlFilteredSignal.setName("jPnlFilteredSignal"); // NOI18N
        jPnlFilteredSignal.setPreferredSize(new java.awt.Dimension(509, 130));
        jPnlFilteredSignal.setLayout(new javax.swing.BoxLayout(jPnlFilteredSignal, javax.swing.BoxLayout.LINE_AXIS));
        jSplitPnl.setTopComponent(jPnlFilteredSignal);

        jPnlFilterConfig.setName("jPnlFilterConfig"); // NOI18N
        jPnlFilterConfig.setPreferredSize(new java.awt.Dimension(509, 130));
        jPnlFilterConfig.setLayout(new java.awt.BorderLayout());

        jPanel1.setName("jPanel1"); // NOI18N
        jPanel1.setPreferredSize(new java.awt.Dimension(734, 231));
        jPanel1.setLayout(new java.awt.BorderLayout());

        org.jdesktop.swingx.border.DropShadowBorder dropShadowBorder1 = new org.jdesktop.swingx.border.DropShadowBorder();
        dropShadowBorder1.setShowLeftShadow(true);
        dropShadowBorder1.setShowTopShadow(true);
        jPnlFreqChart.setBorder(dropShadowBorder1);
        jPnlFreqChart.setMinimumSize(new java.awt.Dimension(307, 231));
        jPnlFreqChart.setName("jPnlFreqChart"); // NOI18N
        jPnlFreqChart.setPreferredSize(new java.awt.Dimension(307, 231));
        jPnlFreqChart.setLayout(new java.awt.BorderLayout());
        jPanel1.add(jPnlFreqChart, java.awt.BorderLayout.CENTER);

        jPanel2.setName("jPanel2"); // NOI18N
        jPanel2.setPreferredSize(new java.awt.Dimension(550, 235));
        jPanel2.setLayout(new java.awt.BorderLayout());

        jPanel3.setMinimumSize(new java.awt.Dimension(451, 59));
        jPanel3.setName("jPanel3"); // NOI18N
        jPanel3.setPreferredSize(new java.awt.Dimension(516, 60));

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(systole.view.SystoleApp.class).getContext().getActionMap(JPnlFilteringDetails.class, this);
        btnPreviewFilter.setAction(actionMap.get("previewFilter")); // NOI18N
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(systole.view.SystoleApp.class).getContext().getResourceMap(JPnlFilteringDetails.class);
        btnPreviewFilter.setIcon(resourceMap.getIcon("btnPreviewFilter.icon")); // NOI18N
        btnPreviewFilter.setText(resourceMap.getString("btnPreviewFilter.text")); // NOI18N
        btnPreviewFilter.setIconTextGap(15);
        btnPreviewFilter.setName("btnPreviewFilter"); // NOI18N

        btnRestoreDefaults.setAction(actionMap.get("restoreDefaults")); // NOI18N
        btnRestoreDefaults.setIcon(resourceMap.getIcon("btnRestoreDefaults.icon")); // NOI18N
        btnRestoreDefaults.setText(resourceMap.getString("btnRestoreDefaults.text")); // NOI18N
        btnRestoreDefaults.setName("btnRestoreDefaults"); // NOI18N

        btnApplyFilter.setAction(actionMap.get("applyChanges")); // NOI18N
        btnApplyFilter.setIcon(resourceMap.getIcon("btnApplyFilter.icon")); // NOI18N
        btnApplyFilter.setText(resourceMap.getString("btnApplyFilter.text")); // NOI18N
        btnApplyFilter.setName("btnApplyFilter"); // NOI18N

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btnPreviewFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(24, 24, 24)
                .addComponent(btnApplyFilter)
                .addGap(18, 18, 18)
                .addComponent(btnRestoreDefaults, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jPanel3Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btnApplyFilter, btnPreviewFilter, btnRestoreDefaults});

        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(btnApplyFilter, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnRestoreDefaults, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnPreviewFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jPanel3Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {btnApplyFilter, btnPreviewFilter, btnRestoreDefaults});

        jPanel2.add(jPanel3, java.awt.BorderLayout.SOUTH);

        jPanel4.setMinimumSize(new java.awt.Dimension(451, 96));
        jPanel4.setName("jPanel4"); // NOI18N
        jPanel4.setPreferredSize(new java.awt.Dimension(451, 96));
        jPanel4.setLayout(new java.awt.GridLayout(2, 1));

        jPanel5.setMinimumSize(new java.awt.Dimension(451, 80));
        jPanel5.setName("jPanel5"); // NOI18N
        jPanel5.setPreferredSize(new java.awt.Dimension(451, 80));

        jLabel9.setFont(resourceMap.getFont("jLabel9.font")); // NOI18N
        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N

        lblSamplingFrequency.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        lblSamplingFrequency.setText(resourceMap.getString("lblSamplingFrequency.text")); // NOI18N
        lblSamplingFrequency.setName("lblSamplingFrequency"); // NOI18N

        lblFilterType.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        lblFilterType.setText(resourceMap.getString("lblFilterType.text")); // NOI18N
        lblFilterType.setName("lblFilterType"); // NOI18N

        jLabel11.setFont(resourceMap.getFont("jLabel11.font")); // NOI18N
        jLabel11.setText(resourceMap.getString("jLabel11.text")); // NOI18N
        jLabel11.setName("jLabel11"); // NOI18N

        lblSamplingPeriod.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblSamplingPeriod.setText(resourceMap.getString("lblSamplingPeriod.text")); // NOI18N
        lblSamplingPeriod.setName("lblSamplingPeriod"); // NOI18N

        jLabel7.setFont(resourceMap.getFont("jLabel7.font")); // NOI18N
        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        lblAlgorithm.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        lblAlgorithm.setText(resourceMap.getString("lblAlgorithm.text")); // NOI18N
        lblAlgorithm.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        lblAlgorithm.setName("lblAlgorithm"); // NOI18N

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(45, 45, 45)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblSamplingPeriod)
                    .addComponent(lblFilterType, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(83, 83, 83)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 38, Short.MAX_VALUE)
                        .addComponent(lblAlgorithm, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 55, Short.MAX_VALUE)
                        .addComponent(lblSamplingFrequency)
                        .addGap(20, 20, 20)))
                .addGap(52, 52, 52))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7)
                            .addComponent(lblAlgorithm, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(lblFilterType))))
                .addGap(18, 18, 18)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblSamplingPeriod)
                    .addComponent(lblSamplingFrequency))
                .addContainerGap(32, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                .addContainerGap(45, Short.MAX_VALUE)
                .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(21, 21, 21))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                .addContainerGap(45, Short.MAX_VALUE)
                .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(21, 21, 21))
        );

        jPanel4.add(jPanel5);

        jPanel6.setName("jPanel6"); // NOI18N

        txtTransitionBandwidth.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter()));
        txtTransitionBandwidth.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtTransitionBandwidth.setText(resourceMap.getString("txtTransitionBandwidth.text")); // NOI18N
        txtTransitionBandwidth.setName("txtTransitionBandwidth"); // NOI18N

        jLabel6.setFont(resourceMap.getFont("jLabel6.font")); // NOI18N
        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        jLabel3.setFont(resourceMap.getFont("jLabel3.font")); // NOI18N
        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel8.setFont(resourceMap.getFont("jLabel8.font")); // NOI18N
        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        spinFilterOrder.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(102), Integer.valueOf(1), null, Integer.valueOf(1)));
        spinFilterOrder.setName("spinFilterOrder"); // NOI18N

        jLabel5.setFont(resourceMap.getFont("jLabel5.font")); // NOI18N
        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        spinFilterIterations.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(2), Integer.valueOf(1), null, Integer.valueOf(1)));
        spinFilterIterations.setName("spinFilterIterations"); // NOI18N

        jLabel2.setFont(resourceMap.getFont("jLabel2.font")); // NOI18N
        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        spinCutoff.setModel(new javax.swing.SpinnerNumberModel(17, 0, 50, 1));
        spinCutoff.setName("spinCutoff"); // NOI18N

        txtAttenuation.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtAttenuation.setText(resourceMap.getString("txtAttenuation.text")); // NOI18N
        txtAttenuation.setName("txtAttenuation"); // NOI18N

        txtRipple.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtRipple.setText(resourceMap.getString("txtRipple.text")); // NOI18N
        txtRipple.setName("txtRipple"); // NOI18N

        jLabel4.setFont(resourceMap.getFont("jLabel4.font")); // NOI18N
        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtTransitionBandwidth, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(spinCutoff, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5)
                    .addComponent(jLabel3))
                .addGap(18, 18, 18)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(spinFilterOrder, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtRipple, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtAttenuation, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(spinFilterIterations, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(21, Short.MAX_VALUE))
        );

        jPanel6Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {spinCutoff, spinFilterIterations, spinFilterOrder, txtAttenuation, txtRipple, txtTransitionBandwidth});

        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(spinCutoff, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(spinFilterOrder, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel8)
                        .addComponent(jLabel3))
                    .addComponent(spinFilterIterations, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(txtTransitionBandwidth, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel5))
                    .addComponent(txtRipple, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(txtAttenuation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jPanel6Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {spinCutoff, spinFilterIterations, spinFilterOrder, txtAttenuation, txtRipple, txtTransitionBandwidth});

        jPanel4.add(jPanel6);

        jPanel2.add(jPanel4, java.awt.BorderLayout.CENTER);

        jPanel1.add(jPanel2, java.awt.BorderLayout.EAST);

        jPnlFilterConfig.add(jPanel1, java.awt.BorderLayout.CENTER);

        jXHeader1.setDescription(resourceMap.getString("jXHeader1.description")); // NOI18N
        jXHeader1.setTitle(resourceMap.getString("jXHeader1.title")); // NOI18N
        jXHeader1.setName("jXHeader1"); // NOI18N
        jPnlFilterConfig.add(jXHeader1, java.awt.BorderLayout.PAGE_START);

        jSplitPnl.setRightComponent(jPnlFilterConfig);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSplitPnl, javax.swing.GroupLayout.DEFAULT_SIZE, 866, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSplitPnl, javax.swing.GroupLayout.DEFAULT_SIZE, 562, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnApplyFilter;
    private javax.swing.JButton btnPreviewFilter;
    private javax.swing.JButton btnRestoreDefaults;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPnlFilterConfig;
    private javax.swing.JPanel jPnlFilteredSignal;
    private javax.swing.JPanel jPnlFreqChart;
    private javax.swing.JSplitPane jSplitPnl;
    private org.jdesktop.swingx.JXHeader jXHeader1;
    private javax.swing.JLabel lblAlgorithm;
    private javax.swing.JLabel lblFilterType;
    private javax.swing.JLabel lblSamplingFrequency;
    private javax.swing.JLabel lblSamplingPeriod;
    private javax.swing.JSpinner spinCutoff;
    private javax.swing.JSpinner spinFilterIterations;
    private javax.swing.JSpinner spinFilterOrder;
    private javax.swing.JFormattedTextField txtAttenuation;
    private javax.swing.JFormattedTextField txtRipple;
    private javax.swing.JFormattedTextField txtTransitionBandwidth;
    // End of variables declaration//GEN-END:variables

    /**
     * @return the jPnlFreqChart
     */
    public javax.swing.JPanel getJPnlFreqChart() {
        return jPnlFreqChart;
    }

    /**
     * @param jPnlFreqChart the jPnlFreqChart to set
     */
    public void setJPnlFreqChart(javax.swing.JPanel jPnlFreqChart) {
        this.jPnlFreqChart = jPnlFreqChart;
    }

    

    /**
     * @param settings
     */
    public void loadSettingsInForm(FilterSettings settings){
        this.spinCutoff.setValue((new Double(settings.getFilt().getCutOffFrequency())).intValue());
        this.spinFilterOrder.setValue(settings.getFConfig().getOrder());
        this.spinFilterIterations.setValue(settings.getDefaultIterations());
        this.txtAttenuation.setText(formatter.format(settings.getFConfig().getAtten()));
        this.txtRipple.setText(formatter.format(settings.getFConfig().getRipple()));
        this.txtTransitionBandwidth.setText(formatter.format(settings.getFConfig().getTrband()));
        this.lblSamplingFrequency.setText(formatter.format(settings.getFilt().getSamplingFrequency()));
        this.lblSamplingPeriod.setText(formatter.format(settings.getFilt().getSamplingPeriod()));
    }


    /**
     * @return FilterSettings
     */
    public FilterSettings setupSettings(){
        double atten = Double.parseDouble(this.txtAttenuation.getText().replace(",", "."));
        double ripple = Double.parseDouble(this.txtRipple.getText().replace(",", "."));
        double trband = Double.parseDouble(this.txtTransitionBandwidth.getText().replace(",", "."));
        int cutoff = ((Integer)this.spinCutoff.getValue()).intValue();
        int iterations = ((Integer)this.spinFilterIterations.getValue()).intValue();
        int order = ((Integer)this.spinFilterOrder.getValue()).intValue();

        FilterSettings newSettings = new FilterSettings();
        newSettings.createDefault(this.logic.getAnalysis().getSignalFrequency().getFrequency().doubleValue());
        newSettings.setDefaultIterations(iterations);
        newSettings.setFilt(new LowPass(newSettings.getFilt().getSamplingPeriod(), (new Double(cutoff)).doubleValue()));
        newSettings.setFConfig(newSettings.getFilt().config(order, atten, ripple, trband));
        newSettings.setFAlg(new RemezEquiripple());

        return newSettings;
    }

    /**
     * 
     */
    @Action
    public void previewFilter(){

        //Llamo a refiltrar - estos debieran ser parametros de esta clase y no de metodo
        Segment refiltered = FilterProcessor.filterPulseWave(this.logic.getAnalysis().getRawSignal().getSegment(), this.setupSettings());

        XYChart previewChart = new XYChart("Señal Filtrada - Vista Previa","Muestras","Amplitud(%)");
        previewChart.setShowLegend(false);
        previewChart.addSeries("", refiltered.toDoubleArray(), 1);

        this.jPnlFilteredSignal.removeAll();
        this.jPnlFilteredSignal.add(previewChart.plot());
        this.jPnlFilteredSignal.revalidate();

        this.btnApplyFilter.setEnabled(true);

    }

    /**
     * 
     */
    @Action
    public void applyChanges(){
        //El filtro se ha modificado
       // this.logic.setFilterIndicators(this.setupSettings());
        //this.logic.getAnalysisStatus().execute();
        this.btnApplyFilter.setEnabled(false);
    }

    /**
     * 
     */
    @Action
    public void restoreDefaults(){
      //  this.loadSettingsInForm(this.logic.getDefaultIndicators());
        //this.logic.setFilterIndicators(this.logic.getDefaultIndicators());
        this.previewFilter();
    }

}
